var e = require;
var t = module;
var o = exports;
var n = o;
Object.defineProperty(n, "__esModule", {value: !0});
var i = e("ADAssetsManager"),
    a = (function () {
        function e() {
            (this._currViewName = ""),
                (this._nativeGeneralAdDisplayState = !1),
                (this._nativeGeneralAdDisplayTag = !0),
                (this._isLoadComplete = !1),
                (this._loadAutoShow = !1),
                (this._isConsume = !1),
                (this._onLoadCallbackRef = null),
                (this._onResizeCallbackRef = null),
                (this._onErrorCallbackRef = null),
                (this._nativeGeneralAdNode = null),
                (this._adData = null);
        }
        return (
            (e.prototype.init = function () {
                console.log("nativeGeneralAd init"),
                    (this._onLoadCallbackRef = this.onNativeGeneralAdLoad.bind(this)),
                    (this._onErrorCallbackRef = this.onNativeGeneralAdError.bind(this)),
                    this.createNativeGeneralAd(!1);
            }),
            (e.prototype.createNativeGeneralAdNode = function () {
                cc.isValid(this._nativeGeneralAdNode) &&
                    (this._nativeGeneralAdNode.destroy(), (this._nativeGeneralAdNode = null));
                var e = i.adAssetsMap.prefabs.NativeGeneralAd;
                this._currViewName && (e = i.adAssetsMap.prefabs[this._currViewName]),
                    (this._nativeGeneralAdNode = i.default.instance.createNodeByPreloading(e)),
                    (this._nativeGeneralAdNode.zIndex = cc.macro.MAX_ZINDEX),
                    this._nativeGeneralAdNode
                        .getChildByName("content")
                        .getChildByName("btn_look")
                        .on("click", this.onClickAD, this),
                    this._nativeGeneralAdNode
                        .getChildByName("content")
                        .getChildByName("ad_img")
                        .on("click", this.onClickAD, this);
                var t = this._nativeGeneralAdNode.getChildByName("content").getChildByName("btn_close");
                t && t.on("click", this.onClickClose, this);
                var o = this._nativeGeneralAdNode.getChildByName("content").getChildByName("btn_continue");
                o && o.on("click", this.onClickClose, this);
            }),
            (e.prototype.destroyNativeGeneralAdNode = function () {
                cc.isValid(this._nativeGeneralAdNode) &&
                    (this._nativeGeneralAdNode.destroy(), (this._nativeGeneralAdNode = null));
            }),
            (e.prototype.showNativeGeneralAd = function (e, t, o) {
                console.log("showNativeGeneralAd", e),
                    (this._currViewName = e),
                    (this._showCallback = t),
                    (this._closeCallback = o),
                    (this._nativeGeneralAdDisplayState = !0);
            }),
            (e.prototype.hideNativeGeneralAd = function (e) {
                console.log("hideNativeGeneralAd", e),
                    (this._nativeGeneralAdDisplayState = !1),
                    (this._showCallback = null);
            }),
            (e.prototype.setNativeGeneralAdDisplayTag = function (e) {
                if ((console.log("setNativeGeneralAdDisplayTag", e), this._nativeGeneralAdDisplayTag != e))
                    if (((this._nativeGeneralAdDisplayTag = e), e))
                        this._nativeGeneralAdDisplayState &&
                            this.showNativeGeneralAd(this._currViewName, this._showCallback);
                    else {
                        var t = this._nativeGeneralAdDisplayState;
                        this.hideNativeGeneralAd(!1), (this._nativeGeneralAdDisplayState = t);
                    }
            }),
            (e.prototype.destroyNativeGeneralAd = function () {
                console.log("destoryNativeGeneralAd"),
                    (this._currViewName = ""),
                    (this._showCallback = null),
                    (this._closeCallback = null),
                    (this._nativeGeneralAdDisplayState = !1),
                    (this._isLoadComplete = !1),
                    (this._loadAutoShow = !1),
                    (this._isConsume = !1),
                    this.destroyNativeGeneralAdNode();
            }),
            (e.prototype.setAdData = function (e, t) {
                var o = this;
                if ((console.log("setAdData", e, t), cc.isValid(this._nativeGeneralAdNode))) {
                    e &&
                        cc.loader.load({url: e, type: "png"}, function (e, t) {
                            if (e) console.error("原生nativeInterstitial img加载失败");
                            else {
                                var n = new cc.SpriteFrame(t);
                                n
                                    ? (o._nativeGeneralAdNode
                                          .getChildByName("content")
                                          .getChildByName("ad_img")
                                          .getComponent(cc.Sprite).spriteFrame = n)
                                    : console.error("原生nativeInterstitial img加载失败");
                            }
                        });
                    var n = this._nativeGeneralAdNode.getChildByName("content").getChildByName("title_node");
                    n && (n.getChildByName("lab_title").getComponent(cc.Label).string = t || "");
                }
            }),
            (e.prototype.onClickClose = function () {
                this.hideNativeGeneralAd(!1),
                    this._closeCallback && this._closeCallback(),
                    (this._closeCallback = null);
            }),
            e
        );
    })();
n.default = a;
